package com.pshcp.patient.api;

import com.framework.base.PageList;
import com.framework.base.ResultBuilder;
import com.framework.base.ResultDTO;
import com.framework.logaop.Log;
import com.framework.logaop.LogSourceEnum;
import com.framework.logaop.LogTypeEnum;
import com.framework.tool.CommonTool;
import com.pshcp.domain.dto.NewsDTO;
import com.pshcp.domain.model.News;
import com.pshcp.domain.vo.NewsVO;
import com.pshcp.patient.domain.news.ao.NewsDetailAO;
import com.pshcp.patient.domain.news.ao.NewsListAO;
import com.pshcp.service.NewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = {"患者端-新闻（医院动态，科普文章）"})
@Slf4j
@RestController
@RequestMapping("/api/patient/news")
public class NewsAPI {

    @Autowired
    private NewsService newsService;

    @ApiOperation("新闻列表")
    @Log(source = LogSourceEnum.PATIENT_APP, type = LogTypeEnum.SELECT, desc = "新闻列表")
    @PostMapping("/list")
    public ResultDTO<PageList<NewsVO>> list(@RequestBody NewsListAO newsListAO){

        PageList<News> pageList = newsService.pageList(CommonTool.copyProperties(newsListAO, NewsDTO.class));

        return ResultBuilder.success(CommonTool.buildPageList(pageList, NewsVO.class));
    }

    @ApiOperation("新闻详情")
    @Log(source = LogSourceEnum.PATIENT_APP, type = LogTypeEnum.SELECT, desc = "新闻列表")
    @PostMapping("/detail")
    public ResultDTO<NewsVO> detail(@RequestBody NewsDetailAO detailAO){

        News news = newsService.findById(detailAO.getId());

        return ResultBuilder.success(CommonTool.copyProperties(news, NewsVO.class));
    }

}
